/*
 * Date：10/23/18 10:08 PM 
 * Author: guomw
 *
 */

package com.treasure.mall.biz.repository.system;

import com.treasure.mall.biz.entity.auth.SystemManager;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * 系统管理员Repository
 *
 * @author guomw
 * @date 2018/9/17
 */
@Repository
public interface SystemManagerRepository extends JpaRepository<SystemManager, Integer>, JpaSpecificationExecutor<SystemManager> {

    /**
     * 更新启用状态
     *
     * @param userId
     * @param enable
     * @return
     */
    @Query("update SystemManager m set m.enable=?2 where m.userId=?1")
    @Modifying(clearAutomatically = true)
    @Transactional(rollbackFor = RuntimeException.class)
    int updateEnableById(Integer userId, boolean enable);

    /**
     * 修改密码
     *
     * @param userId
     * @param newpass
     */
    @Query("update SystemManager  m set m.loginPwd=?2 where m.userId=?1")
    @Modifying(clearAutomatically = true)
    @Transactional(rollbackFor = RuntimeException.class)
    void modifyPassword(Integer userId, String newpass);
}
